import requests

# 前置条件，先登录
login_url="http://192.168.0.106:8080/account/token"
login_headers=None
login_data = {
    "name": "test",
    "password": "test123"
}
login_response=requests.post(url=login_url, json=login_data)
print(login_response.json())

# 1）实例化一个会话对象
session = requests.Session()

# 2）发送请求
# 2.1）get请求，查看账号列表的数据
user_url = "http://192.168.0.106:8080/account?page=1&size=9"
user_header={"Authorization": login_response.json()["data"]}
user_response = session.get(url=user_url,headers=user_header)
print(user_response.text)
# 2.2）post请求，查看随机变量的数据
variable_url = "http://192.168.0.106:8080/variables/search"
variable_header = {"Authorization": login_response.json()["data"]}
variable_data = {"page": 1, "size": 10, "variablesname": "", "projectid": "1"}

variable_response = session.post(url=variable_url, headers=variable_header, json=variable_data)
print(variable_response.text)

# 直接调用request函数发送请求
response = requests.request(method="post", url=login_url, json=login_data)
print(response.text)